package com.mbuswidget;

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Utils {
	static public String getTextValue(Element ele, String tagName) {
		String textVal = null;
		NodeList nl = ele.getElementsByTagName(tagName);
		
		if(nl != null && nl.getLength() > 0) {
			Element el = (Element)nl.item(0);
			textVal = el.getFirstChild().getNodeValue();
		}

		return textVal;
	}
	
	static private void qsort(ArrayList<String> n, ArrayList<Double> d, int left, int right){
		int x = left, y = right;
		Double pivot = d.get((left+right)/2);
		while (x <= y){
			while (d.get(x) < pivot) x++;
			while (d.get(y) > pivot) y--;
			if (x <= y){
				String temp1 = n.get(x);
				n.set(x, n.get(y));
				n.set(y, temp1);
				Double temp2 = d.get(x);
				d.set(x, d.get(y));
				d.set(y, temp2);
			}
		}
		if (left < y) qsort(n, d, left, y);
		if (x < right) qsort(n, d, x, right);
	}
	
	static public void quicksort(ArrayList<String> names, ArrayList<Double> dist){
		qsort(names, dist, 0, names.size()-1);
	}
}